<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:mo="https://gitee.com/aun/Timo">
<body>

    <form  class="layui-card layui-form" data-auto="true" action="/pcs/project/inspection/save"   method="post" data-table-id="ProjectInspectionTable">

        <input type="hidden" name="id" th:if="${vo}" th:value="${vo.id}"/>

        <div class="layui-card-body padding-15">
            <div class="layui-form-item">
                <label class="layui-form-label ">项目类型</label>
                <div class="layui-input-block ">
                    <select name="type"  required class="layui-input">
                        <option value="2" th:selected="${vo?.type == 2}"  >陪诊</option>
                        <option value="3" th:selected="${vo?.type == 3}"  >陪检</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">项目图片</label>
                <div class="layui-input-block ">
                    <input type="hidden"  name="img" th:value="${vo?.img}" >
                    <script>$("[name=img]").uploadOneImageNew();</script>
                    <style>
                        .uploadimage, .uploadfile{
                            width: 78px!important;
                            height: 78px!important;
                        }
                    </style>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">项目名称</label>
                <div class="layui-input-block ">
                    <input type="text" name="title" required  th:value="${vo?.title}"  class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label ">服务合同</label>
                <div class="layui-input-block ">
                    <select name="isNeedSignContract" lay-filter="isNeedSignContract"  required class="layui-input">
                        <option value="0" th:selected="${vo?.isNeedSignContract == 0}"  >无需签订合同</option>
                        <option value="1" th:selected="${vo?.isNeedSignContract == 1}"  >需要签订合同</option>
                    </select>
                </div>
            </div>

            <th:block th:if="${vo?.isNeedSignContract == 1}">
                <div class="layui-form-item" >
                    <label class="layui-form-label ">选择合同</label>
                    <div class="layui-input-block ">
                        <select name="contractTplId"  required class="layui-input">
                            <th:block>
                                <th:block th:each="item:${contractTplList}">
                                    <option th:value="${item.id}" th:text="${item.title}" th:selected="${item.id == vo?.contractTplId}"></option>
                                </th:block>
                            </th:block>

                        </select>
                    </div>
                </div>
            </th:block>
            <th:block th:else>
                <div class="layui-form-item" style="display: none">
                    <label class="layui-form-label ">选择合同</label>
                    <div class="layui-input-block ">
                        <select name="contractTplId"  required class="layui-input">
                            <th:block>
                                <th:block th:each="item:${contractTplList}">
                                    <option th:value="${item.id}" th:text="${item.title}" th:selected="${item.id == vo?.contractTplId}"></option>
                                </th:block>
                            </th:block>

                        </select>
                    </div>
                </div>
            </th:block>



            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label ">陪护价格</label>
                    <div class="layui-input-block ">
                        <input type="text" name="price" required  th:value="${vo?.price}"  class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">护工佣金比例</label>
                    <div class="layui-input-inline">
                        <div class="layui-input-group">

                            <input type="text" name="commissionRate"   th:value="${vo?.commissionRate}"  class="layui-input">
                            <div class="layui-input-split layui-input-suffix">
                                %
                            </div>
                        </div>

                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label ">服务说明</label>
                <div class="layui-input-block ">
                    <textarea placeholder="请输入服务说明" class="layui-textarea" name="content">[[${vo?.content}]]</textarea>
                </div>
            </div>



            <div class="text-center layui-form-actions1">
                <button class="layui-btn" type="submit">保存</button>
                <button class="layui-btn layui-btn-danger" data-close data-confirm="确定要取消编辑吗？" type='button'>关闭</button>
            </div>

        </div>
    </form>
    <script>

    </script>
<script>
    let editor;
    require(['ckeditor5'], function () {
        editor = window.createEditor('[name="content"]');
    })
    layui.use(function(){
        var form = layui.form;
        var layer = layui.layer;
        form.on('select(isNeedSignContract)', function(data){
            console.log(data)
            var value = data.value; // 获得被选中的值
            if(value == 1){
                $("[name=contractTplId]").parent().parent().show();
            }else{
                $("[name=contractTplId]").parent().parent().hide();
            }

        });
        window.submit_save = function(){
            console.log("111111111111");


        }
        form.on('submit(demo-submit)', function(data){
            console.log("222222222222",data);
            let fields = data.field;
            if(fields.isNeedSignContract=="1"){
                if(!fields.contractTplId){
                    layer.msg("请选择合同");
                    return false;
                }
            }
            field.content = encodeURIComponent(field.content);
            $.ajax({
                url: "/pcs/project/inspection/save",
                type: "POST",
                data: fields,
                success: function (res) {
                    console.log(res)
                    if(res.code==1){
                        layer.msg("操作成功",{icon:1,time:1000},function () {
                            //刷新当前页
                            window.location.reload();
                        })
                    }else{
                        layer.msg(res.info,{icon:2,time:1000})
                    }
                }
            })
            return false;
        })

    })
</script>


</body>
</html>